package com.liuqi.knet.remoting.exchange;

import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

/**
 * 响应
 *
 * @author liuqi
 * @date 2024/12/17 15:13
 **/
@Getter
@Setter
@ToString
public class Response {

    // ========== 响应状态码

    /**
     * ok
     */
    public static final byte OK = 20;

    /**
     * fail
     */
    public static final byte FAIL = 30;

    /**
     * response timeout
     */
    public static final byte RESPONSE_TIMEOUT = 40;

    /**
     * client error.
     */
    public static final byte CLIENT_ERROR = 50;

    /**
     * service error.
     */
    public static final byte SERVICE_ERROR = 60;

    /**
     * internal error.
     */
    public static final byte INTERNAL_ERROR = 90;

    /**
     * 消息ID
     */
    private long id;

    /**
     * 状态码
     */
    private byte state;

    /**
     * 错误信息
     */
    private String errorMessage;

    /**
     * 响应数据
     */
    private Object result;

    public Response() {
    }

    public Response(long id) {
        this.id = id;
    }

    public Response(long id, Object result) {
        this.id = id;
        this.state = OK;
        this.result = result;
    }

    public boolean isOk() {
        return this.state == Response.OK;
    }

}
